﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SuperMarketSystem
{
    public class MyMysqlUtils
    {
        public static MySqlConnection getMySqlConnection()//获取一个mysql数据库连接
        {
            String loginConnection = "server=localhost;user id=root;password=root;database=sm";
            MySqlConnection connectionLogin = new MySqlConnection(loginConnection);
            try
            {
                connectionLogin.Open();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.StackTrace);
            }
            return connectionLogin;
        }
        public static void closeMysqlConnection(MySqlConnection connectionLogin)//关闭一个mysql数据库连接
        {
            try
            {
                connectionLogin.Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.StackTrace);
            }
        }
    }
}
